<template>
	<view>
		<web-view  :src="pageUrl" @message="messageHandle"></web-view>
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters,
		mapMutation,
		mapActions
	} from "vuex";
	export default {
		computed: {
			...mapState({
				isLogin:state=>state.user.isLogin,
				userInfo: state => state.user.userInfo,

			})
		
		},
		data() {
			return {
				pageUrl:''
			}
		},
		methods: {
			messageHandle(e){
				if(e.detail.data[0].action=="login"){		//登录回传
					this.$store.commit("userInfo", e.detail.data[0].payload);
					this.$store.commit("token", e.detail.data[0].payload.token);
					this.$store.commit("isLogin", true);
				}else if(e.detail.data[0].action=="toPage"){
					this.toPage({
						url:e.detail.data[0].payload.url
					})
				}else if(e.detail.data[0].action=="share"){
					this.share()
				}else if(e.detail.data[0].action=="autoLogin"){
					this.$store.commit("token",e.detail.data[0].payload.token)
				}else{
					console.log("no action");
				}
			},
			share(){
				
			}
		},
		onLoad(option){
			let _url='';
			if(this.isLogin){
				if(option.url.indexOf('?')>-1){
					_url=decodeURIComponent(option.url+'&token='+this.userInfo.token)
				}else{
					_url=decodeURIComponent(option.url+'?token='+this.userInfo.token)
				}
			}else{
				_url=decodeURIComponent(option.url)
			}
			this.pageUrl=_url;
		},
		onPullDownRefresh() {
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1500)
		}
	}
</script>

<style>

</style>
